/*
 * Copyright (c) 2014 Steve Tracey
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.stevetracey.common;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Properties;



public class Configuration
{

	private static Log log = LogFactory.getLog(Configuration.class);
	private static String CONFIG_FILE = "/Application.properties";
	private static Configuration instance;
	private Properties props = new Properties();

	private Configuration()
	{
		try
		{
			log.debug("Loading application configuration from " + CONFIG_FILE);
			props.load(getClass().getResourceAsStream(CONFIG_FILE));
			log.debug("Loaded " + props.size() + " configuration items");
		}
		catch (Exception e)
		{
			log.error("Failed to load configuration...", e);
		}
	}

	public static String getValue(String pKey) {
		if (instance == null) instance = new Configuration();

		return instance.props.getProperty(pKey);
	}

	public static int getIntValue(String pKey) {
		return Integer.parseInt(getValue(pKey));
	}

	public static double getDoubleValue(String pKey) {
		return Double.parseDouble(getValue(pKey));
	}

	public static boolean getBooleanValue(String pKey) {
		return getValue(pKey).equals("true");
	}
}
